package indi.zhifa.recipe.bailan.framework.common.util;

import java.util.HashMap;
import java.util.Map;

/**
 * Description: 
 * @Copyright: Copyright (c) 2020-2028 北京华咨电力科技发展有限公司 All rights reserved.
 * @author: 褚智勇(hataksumo@163.com)
 * @date:  2021/12/4 20:58
 */
public class MyURIEncoder {

    public static String encodeURIComponent(String input,boolean pErase) {
        Map<Integer,String> rpMap = new HashMap<Integer,String>(){{
            put('+'-0,"%2B");
            put(' '-0,"%20");
            put('/'-0,"%2F");
            put('?'-0,"%3F");
            put('%'-0,"%25");
            put('#'-0,"%23");
            put('&'-0,"%26");
            put('='-0,"%3D");
        }};
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<input.length();i++){
            char c = input.charAt(i);
            if(rpMap.containsKey(c-0)){
                if(!pErase){
                    sb.append(rpMap.get(c-0));
                }
            }else{
                sb.append(c);
            }
        }
        return sb.toString();
    }

}
